package com.fly.container.aware;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

/**
 * @author Mr.Fu
 * @date 2025/3/10 23:29
 */
@Service
public class SearchBeanNameAware implements BeanNameAware, BeanPostProcessor {

    public SearchBeanNameAware() {
        System.out.println("SearchBeanNameAware 构造方法被执行");
    }

    @Override
    public void setBeanName(String s) {
        System.out.println("SearchBeanNameAware:" + s);
    }

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
//        if ("searchBeanNameAware".equals(beanName)) {
            System.out.println("SearchBeanNameAware before beanName:" + beanName);
//        }
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if ("searchBeanNameAware".equals(beanName)) {
            System.out.println("SearchBeanNameAware after beanName:" + beanName);
        }
        return bean;
    }
}
